package com.yinp.proapp.module.customview.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.yinp.proapp.R;
import com.yinp.proapp.base.activity.AppBaseActivity;
import com.yinp.proapp.databinding.ActivityCustomViewBinding;
import com.yinp.proapp.module.customview.adapter.CustomViewAdapter;
import com.yinp.proapp.module.customview.bean.CustomViewBean;
import com.yinp.proapp.utils.AppUtils;
import com.yinp.proapp.utils.StatusBarUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义的view
 */
public class CustomViewActivity extends AppBaseActivity<ActivityCustomViewBinding> {

    private CustomViewAdapter adapter;
    private List<CustomViewBean> mList = new ArrayList<>();

    @Override
    protected void initViews() {
        setStatusBarHeight(StatusBarUtil.getStatusBarHeight(mContext));

        initClick(bd.header.headerBackImg);
        bd.header.headerCenterTitle.setText("自定义view");
        initRecycler();
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v == bd.header.headerBackImg) {
            finish();
        }
    }

    private void initRecycler() {
        /**
         * 复制加更改的
         */
        mList.add(new CustomViewBean(CustomViewBean.Text, "通过已有知识自己想的做的"));
        mList.add(new CustomViewBean(CustomViewBean.MeView, "带三角形的圆角布局", "com.yinp.proapp.module.customview.activity.TestTriangleActivity", ""));
        mList.add(new CustomViewBean(CustomViewBean.MeView, "一些奇特的view", "com.yinp.proapp.module.customview.activity.PeculiarActivity", ""));
        mList.add(new CustomViewBean(CustomViewBean.MeView, "一个自定义的数字加减器", "com.yinp.proapp.module.customview.activity.AddSubtractActivity", ""));
        mList.add(new CustomViewBean(CustomViewBean.MeView, "自定义下拉刷新", "com.yinp.proapp.module.customview.activity.MRefreshActivity", ""));
        mList.add(new CustomViewBean(CustomViewBean.MeView, "一些简单的view", "com.yinp.proapp.module.customview.simpleness_view.activity.SimplenessViewActivity", ""));
        mList.add(new CustomViewBean(CustomViewBean.MeView, "进度圆环圆饼", "com.yinp.proapp.module.customview.activity.TestCircleActivity", ""));
        mList.add(new CustomViewBean(CustomViewBean.Text, "复制其它的做更改的"));
        mList.add(new CustomViewBean(CustomViewBean.MixedView, "点击屏幕显示点击范围的图片，可以滑动，显示范围随着滑动改变"
                , "com.yinp.proapp.module.customview.activity.TestClipCircleActivity", ""));
        adapter = new CustomViewAdapter(mList);
        bd.rvList.setLayoutManager(new LinearLayoutManager(mContext));
        bd.rvList.setHasFixedSize(true);
        bd.rvList.setAdapter(adapter);

        adapter.setFooterView(AppUtils.getBlankView(mContext));

        adapter.setOnItemClickListener((adapter, view, position) -> {
            if (!TextUtils.isEmpty(mList.get(position).getUrl())) {
                goToActivity(mContext, mList.get(position).getUrl());
            }
        });
        adapter.setOnItemChildClickListener((adapter, view, position) -> {
            switch (view.getId()) {
                case R.id.stvThink:
                    if (!TextUtils.isEmpty(mList.get(position).getUrl2())) {
                        goToActivity(mContext, mList.get(position).getUrl2());
                    }else {
                        showToast("暂无");
                    }
                    break;
            }
        });
    }
}